package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseModel;
import com.ruoyi.base.service.IBaseModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 型号Controller
 * 
 * @author yepanpan
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/base/model")
public class BaseModelController extends BaseController
{
    @Autowired
    private IBaseModelService baseModelService;

    /**
     * 查询型号列表
     */
    @GetMapping("/select")
    public AjaxResult select(BaseModel baseModel)
    {
        List<BaseModel> list = baseModelService.selectBaseModelList(baseModel);
        return success(list);
    }

    /**
     * 查询型号列表
     */
    @PreAuthorize("@ss.hasPermi('base:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseModel baseModel)
    {
        startPage();
        List<BaseModel> list = baseModelService.selectBaseModelList(baseModel);
        return getDataTable(list);
    }

    /**
     * 导出型号列表
     */
    @PreAuthorize("@ss.hasPermi('base:model:export')")
    @Log(title = "型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseModel baseModel)
    {
        List<BaseModel> list = baseModelService.selectBaseModelList(baseModel);
        ExcelUtil<BaseModel> util = new ExcelUtil<BaseModel>(BaseModel.class);
        util.exportExcel(response, list, "型号数据");
    }

    /**
     * 获取型号详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:model:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseModelService.selectBaseModelById(id));
    }

    /**
     * 新增型号
     */
    @PreAuthorize("@ss.hasPermi('base:model:add')")
    @Log(title = "型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseModel baseModel)
    {
        return toAjax(baseModelService.insertBaseModel(baseModel));
    }

    /**
     * 修改型号
     */
    @PreAuthorize("@ss.hasPermi('base:model:edit')")
    @Log(title = "型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseModel baseModel)
    {
        return toAjax(baseModelService.updateBaseModel(baseModel));
    }

    /**
     * 删除型号
     */
    @PreAuthorize("@ss.hasPermi('base:model:remove')")
    @Log(title = "型号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseModelService.deleteBaseModelByIds(ids));
    }
}
